﻿using Nasty.Core.Session;
using Nasty.Core.Entity;
using SqlSugar;
using Nasty.Core.Attributes;

namespace Nasty.Core.Entity.System
{
    [SugarTable("SysPost", TableDescription = "岗位")]
    public class Post : StandardEntity<Post>
    {
        /// <summary>
        /// 名称
        /// </summary>
        [NastyColumn(ColumnName = "Name", ColumnDescription = "名称", Required = true)]
        public string? Name { get; set; }

        /// <summary>
        /// 编码
        /// </summary>
        [NastyColumn(ColumnName = "Code", ColumnDescription = "编码", IsRepeat = true)]
        public string? Code { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        [SugarColumn(ColumnName = "Description", IsNullable = true, ColumnDescription = "描述")]
        public string? Description { get; set; }

        public override void OnPreAdd()
        {
            base.OnPreAdd();

            var db = AppSession.CurrentDb.Value;
            //var isAny = db.Queryable<Post>().Where((t) => t.Code == this.Code).Any();
            //if (isAny) throw new Exception("编码重复");
        }
    }
}
